package com.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.entity.Clock;
import com.mapper.ClockMapper;
import com.service.ClockService;
import com.service.sys.DepartmentService;
import com.service.sys.UserVoService;
import com.vo.ClockVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author clay
 * @since 2022-03-27
 */
@Service
public class ClockServiceImpl extends ServiceImpl<ClockMapper, Clock> implements ClockService {

    @Resource
    private ClockMapper clockMapper;

    @Resource
    private DepartmentService departmentService;

    @Resource
    private UserVoService userVoService;

    @Override
    public List<ClockVo> select(Clock clock) {
        System.out.println("clock!!!!!");
        List<Clock> clockList = clockMapper.getClockVoByClock(clock);
        List<ClockVo> clockVoList = new ArrayList<>();
        clockList.forEach(c -> {
            ClockVo newClockVo = new ClockVo();
            //将一个对象中的属性值赋值（拷贝）给另一个对象中对应的属性
            BeanUtils.copyProperties(c, newClockVo);
            newClockVo.setDepartment(departmentService.getById(newClockVo.getDepartmentId()));
            newClockVo.setUserVo(userVoService.getById(newClockVo.getUserId()));
            //把实体类添加到clockVoList集合中
            clockVoList.add(newClockVo);
        });
        return clockVoList;
    }

}
